<template>
	<view>
		<u-button  @click="getuser"  style="width: 250rpx;" type="primary" text="确定授权"></u-button>
		
	</view>
</template>

<script>
	// 调取接口
	import {getlogin} from '@/api/api.js'
	export default{
		data(){
			code:'';
			nickname:'';
			avatarurl:''
		},
		methods:{
		
		    getuser(){
	
			   uni.getUserProfile({
				   desc:'获取个人信息',
				   success: (res) => {
				   	 console.log(res);
					 this.nickname=res.userInfo.nickName
					 this.avatarurl=res.userInfo.avatarUrl
					 uni.login({
					 				success: (res) => {
					 					// console.log(res);
					 						this.code=res.code;
					 						
											let obj={
												appid:"wxd8c1fe11c34fd292",
												secret:"141d0ac1af46cc87696894fb6e91e775",
												nickName:this.nickname,
												avatarUrl:this.avatarurl,
												code:this.code
											}
											getlogin(obj).then(res=>{
												// console.log(res,59);
												uni.setStorageSync('wxuser',res.data)
												 setTimeout(()=>{
													uni.navigateBack({
														delta:1
													})
												 },700)
												
											})
					 						// console.log(this.code);
					 					
					 				},
					 				fail: (err) => {
					 					console.log(err);
					 				}
					 			})
				   },
				   complete: (err) => {
				   	console.log(err);
				   }
			   })
				
	
				
			}
			
		},
		onLoad() {
			
		},
		
		onshow(){
			
		}
	}
</script>

<style>
</style>